<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/icons-extra.css" rel="stylesheet" />
		<link href="../css/iconfont.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
		<style type="text/css">
			[ng-cloak] {
				display: none;
			}
		</style>

		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/common/bottom.js"></script>
		<script src="../js/service/myOldService.js"></script>
		<script src="../js/service/userService.js"></script>
		<script src="../js/service/couponService.js"></script>
	</head>

	<body ng-app="mainApp" ng-controller="myOldCtrl">
		<header class="mui-bar mui-bar-nav mui-bar-in">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<div class="mui-input-row mui-search ">
				<input type="search" class="mui-input-clear" placeholder="" id="oldSearch" placeholder="请输入旧物名称">
			</div>
			<a class="mui-icon mui-pull-right right" ng-click="searchOld()">搜索</a>
		</header>
		<!-- 主页面内容容器 -->
		<div class="mui-content order-content mui-scroll-wrapper" id="pullrefresh">
			<div class="mui-scroll">
				<div class="mui-content " style="padding-bottom: 65px;">
					<!-- 主界面具体展示内容 -->
					<ul class="mui-table-view cart">
						<li class="mui-table-view-cell mui-media" ng-repeat="myOld in myOldList">
							<div class="mui-right">

								<div class="mui-pull-left">
									<a href="#">
										<img ng-if="myOld.ifPic" class="mui-media-object "  src="{{baseUrl+'/dapi/download/getImageIO?imgUrl='+myOld.iconUrl|getImgUrl}}" >
										<img ng-if="!myOld.ifPic" class="mui-media-object " ng-src="../images/goodsDefault.gif">
									</a>
								</div>
								<div class="mui-media-body">

									<h5><a href="#"  ng-click="goodsDetailPage(myOld.id,'detail')">{{myOld.title}}约{{myOld.perWeight}}克</a></h5>
									<p class="mui-ellipsis">¥{{myOld.price*myOld.perWeight}}</p>
								</div>
								<div class="mui-media-body">
									<h5>
										<button type="button"  class="mui-btn mui-btn-royal mui-btn-outlined"  ng-click="goodsDetailPage(myOld.id,'update')">修改</button>
										&nbsp;&nbsp;&nbsp;
										<button type="button" ng-show="oldPerm" class="mui-btn mui-btn-royal mui-btn-outlined" ng-click="updateDeal(myOld.id)">审核</button>
									</h5>
								</div>
							</div>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<script type="text/javascript ">
			mui.init();

			mui('.bottomPopover').popover('toggle'); //show hide toggle
		</script>
		<script>
			(function($) {
				$.init({
					swipeBack: true //启用右滑关闭功能
				});
				$(".mui-scroll-wrapper").scroll({
					bounce: false, //滚动条是否有弹力默认是true
					indicators: false, //是否显示滚动条,默认是true
				});
			})(mui);

			mainApp.controller('myOldCtrl', function($scope, $http, myOldService, userService) {
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							//callback: pulldownRefresh
						},
						up: {
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});

				function pullupRefresh() {
					setTimeout(function() {
						getList();
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(); //refresh completed
					}, 1000);
				}

				$scope.baseUrl = baseUrl;
				$scope.pageIndex = 1;
				$scope.pageSize = 10;
				$scope.myOldList = null;
				var getList = function() {
					$scope.oldSearch=document.getElementById("oldSearch").value;
					myOldService.getMyOldList({title:$scope.oldSearch}, $scope.pageIndex, $scope.pageSize, function(data) {
						var myOldList_ = data.data;
						if($scope.pageIndex == 1) {
							$scope.myOldList = myOldList_;
						} else {
							angular.forEach(myOldList_, function(myOld) {
								$scope.myOldList.push(myOld);
							});
						}
						if(myOldList_.length > 0) {
							$scope.pageIndex = $scope.pageIndex + 1;
						}
					}, function(err) {});
				}
				getList();
				$scope.searchOld=function(){
					$scope.pageIndex =1;
					getList();
				}
				$scope.goodsDetailPage = function(id, str) {
					mui.openWindow({ //这里跳转到我的旧物列表页
						url: 'oldSellUpdate.html',
						id: 'oldSellUpdate' + new Date().getMilliseconds(),
						preload: true,
						show: {
							aniShow: 'pop-in'
						},
						waiting: {
							autoShow: false
						},
						extras: {
							oldId: id,
							upOrDe: str
						}
					});
				}
				$scope.updateDeal = function(id, str) {
					mui.openWindow({ //这里跳转到我的旧物列表页
						url: 'oldSelVerify.html',
						id: 'oldSelVerify' + new Date().getMilliseconds(),
						preload: true,
						show: {
							aniShow: 'pop-in'
						},
						waiting: {
							autoShow: false
						},
						extras: {
							oldId: id
						}
					});
				}
				userService.getUserDetail(function(data) {
					$scope.oldPerm = false;
					angular.forEach(data.data.permCodeList, function(perm) {
						if(perm == "oldManager") {
							$scope.oldPerm = true;
						}
					})
				}, error)
			});
		</script>
	</body>

</html>